#include "dd_obb.h"

#include "util/mmgr.h"		// Needs to come in early

using namespace dd;

OBB::OBB()
{

}

OBB::~OBB()
{

}

void OBB::Render(DBG_BUFFER* _pBuffer)
{
	// 
	//		  *------ * MAX
	//		 /		 /|
	//		* ----- * |
	//		|		| *
	//		|		|/
	//	MIN	* ----- *

	math::Vec3 Pos		= m_Mat.GetPos();
	math::Vec3 Up		= m_Mat.GetUp() * m_Size.y;
	math::Vec3 Right	= m_Mat.GetRight() * m_Size.x;
	math::Vec3 Dir		= m_Mat.GetDir() * m_Size.z;
	math::Vec3 Side	= (Up + Right + Dir)*0.5f;
	math::Vec3	Min		= Pos - Side;
	math::Vec3	Max		= Pos + Side;

	// Min corner:
	AddLine(_pBuffer, Min, Min + Dir, m_Color);
	AddLine(_pBuffer, Min, Min + Right, m_Color);
	AddLine(_pBuffer, Min, Min + Up, m_Color);

	// Max corner:
	AddLine(_pBuffer, Max, Max - Dir, m_Color);
	AddLine(_pBuffer, Max, Max - Right, m_Color);
	AddLine(_pBuffer, Max, Max - Up, m_Color);

	// Missing Y axis
	AddLine(_pBuffer, Max-Dir, Max - Dir - Up, m_Color);
	AddLine(_pBuffer, Min+Dir, Min + Dir + Up, m_Color);

	// Missing Z axis
	AddLine(_pBuffer, Max-Up, Max - Up - Dir, m_Color);
	AddLine(_pBuffer, Min+Up, Min + Up + Dir, m_Color);

	// Missing X Axis
	AddLine(_pBuffer, Max-Up, Max - Up - Right, m_Color);
	AddLine(_pBuffer, Min+Up, Min + Up + Right, m_Color);
}

void OBB::Setup(const math::Vec3& _Size, const math::Mat4x4& _Mat, COLOR _Color)
{
	m_Color = _Color;
	m_Size	= _Size;
	m_Mat	= _Mat;
}
